package com.dwxt.community.admin.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.common.base.StatusCode;
import com.dwxt.community.admin.service.InformationLocationService;
import com.dwxt.community.entity.AdLocation;
import com.dwxt.community.entity.InformationWithBLOBs;
import com.dwxt.community.entity.vo.InfomationLocationVo;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 资讯 后台管理
 *
 * @author shenwenkang
 */
@RestController
@RequestMapping("/cms/admin/informationLocation")
public class InformationLocationControllerAdmin {

    @Autowired
    private InformationLocationService informationLocationService;

    /**
     * showdoc
     * @catalog 社区后台管理/资讯
     * @title 获取资讯位置列表
     * @description 获取资讯位置列表
     * @method get
     * @url /cms/admin/informationLocationLocation/get
     * @param pageNum         非必须 Integer 当前页
     * @param pageSize        非必须 Integer 条数
     * @param type            非必须 String 资讯类型
     *
     */
    @GetMapping("/get")
    public BaseResult get(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          String type) {
        if (StringUtils.isBlank(type)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationLocationService.get(pageNum, pageSize, type);
    }
 @GetMapping("/getLocationType")
    public BaseResult getLocationType() {
        return informationLocationService.getLocationType();
    }

    /**
     * showdoc
     * @catalog 社区后台管理/资讯
     * @title 删除位置
     * @method get
     * @description 删除位置
     * @url /cms/admin/informationLocationLocation/del
     * @param id 必须 String 位置ID
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/del")
    public BaseResult del(String id) {
        if (StringUtils.isBlank(id)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationLocationService.del(id);
    }

    /**
     * showdoc
     * @catalog 社区后台管理/资讯
     * @title 删除位置上的资讯
     * @method get
     * @description 删除位置上的资讯
     * @url /cms/admin/informationLocationLocation/delInformationForLocation
     * @param id 必须 String 资讯ID
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/delInformationForLocation")
    public BaseResult delInformationForLocation(String id) {
        if (StringUtils.isBlank(id)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationLocationService.delInformationForLocation(id);
    }


    @PostMapping("/insert")
    public BaseResult insert(@Validated AdLocation adLocation) {
        return informationLocationService.insert(adLocation);

    }


    @PostMapping("/update")
    public BaseResult update(String locationId, String informationId) {
        if (StringUtils.isBlank(locationId) || StringUtils.isBlank(informationId) ) {
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationLocationService.update(locationId,informationId);
    }
}
